#include <iostream>

#include "TDI.hpp"


using namespace std;


TableDesIdentificateurs::TableDesIdentificateurs(){}
TableDesIdentificateurs::~TableDesIdentificateurs(){

	unsigned int size = tableId.size();
	for (unsigned int i = 0; i < size;i++) delete tableId[i];
	tableId.clear();
}




int TableDesIdentificateurs::ajouterIdent(string id){

	//cout << "Ajout de " << id << endl;

	unsigned int numElem  = getPosId(&id);
	
	 if(numElem == tableId.size())tableId.push_back(new string(id));  //copie
	
	//cout << "taille TDI " <<tableId.size() << endl;
	
	
	return numElem;
}


int TableDesIdentificateurs::ajouterAutre(string id)
{
	unsigned int numElem = tableId.size();
	tableId.push_back(new string(id));

	return numElem;
}



int TableDesIdentificateurs::getPosId(string* id)
{
	int temp = tableId.size();


	for (unsigned int i = 0; i < tableId.size(); i++)
	{
		
        	if (*tableId[i] == *id)
		{
			temp = i;
			break;
		}
            		
	}
	return temp;
}


void TableDesIdentificateurs::afficherTable()
{
	for (unsigned int i = 0; i < tableId.size(); i++)
		cout << i << " | " << *tableId[i] << endl;
}


string TableDesIdentificateurs::getElement(int posId)
{
	return *tableId[posId];
}
